from fastapi.responses import JSONResponse
from pydantic import conint

from common.base.base_routers import get_custom_router
from services.dsp.api import DspApi
from services.dsp.schemas.configs import Delays, DspModesConfig, DspSubchannelsControl, DspConfig
from services.dsp.api import _CONFIGS_LITERAL, _COE_LITERAL, _COE_FILE_LITERAL, _CALIBRATION_TYPE_LITERAL


dsp_api = DspApi()
dsp_router = get_custom_router(dsp_api, prefix='/dsp', tags=['dsp'])


@dsp_router.post('/set-dsp-config/', response_class=JSONResponse)
async def set_dsp_config(name: _CONFIGS_LITERAL, config: DspConfig):
    return await dsp_api.set_dsp_config(name, config)


@dsp_router.post('/set-dsp-modes/', response_class=JSONResponse)
async def set_dsp_modes(modes: DspModesConfig):
    return await dsp_api.set_dsp_modes(modes)


@dsp_router.get('/set-typical-coe/', response_class=JSONResponse)
async def set_typical_coe(name: _COE_LITERAL, index: conint(ge=1, le=4), file_name: _COE_FILE_LITERAL):
    return await dsp_api.set_typical_coe(name, index, file_name)


@dsp_router.get('/set-custom-hex-coe/', response_class=JSONResponse)
async def set_custom_hex_coe(name: _COE_LITERAL, index: conint(ge=1, le=4), offset_bw_bands: int):
    return await dsp_api.set_custom_hex_coe(name, index, offset_bw_bands)


@dsp_router.post('/set-channels-control/', response_class=JSONResponse)
async def set_channels_control(index: conint(ge=0, le=1), control: DspSubchannelsControl):
    return await dsp_api.set_channels_control(index, control)


@dsp_router.post('/set_delays-config/', response_class=JSONResponse)
async def set_delays_config(delays: Delays):
    return await dsp_api.set_delays_config(delays)


@dsp_router.get('/get-dsp-config/', response_class=JSONResponse)
async def get_dsp_config(name: _CONFIGS_LITERAL):
    return await dsp_api.get_dsp_config(name)


@dsp_router.get('/get-dsp-modes/', response_class=JSONResponse)
async def get_dsp_modes():
    return await dsp_api.get_dsp_modes()


@dsp_router.get('/get-coe/', response_class=JSONResponse)
async def get_coe(name: _COE_LITERAL, index: conint(ge=1, le=4)):
    return await dsp_api.get_coe(name, index)


@dsp_router.get('/get-channels-control/', response_class=JSONResponse)
async def get_channels_control(index: conint(ge=0, le=1)):
    return await dsp_api.get_channels_control(index)


@dsp_router.get('/disable-calibration-config/', response_class=JSONResponse)
async def disable_calibration_config():
    return await dsp_api.disable_calibration_config()


@dsp_router.get('/enable-calibration-config/', response_class=JSONResponse)
async def enable_calibration_config(calibration_type: _CALIBRATION_TYPE_LITERAL):
    return await dsp_api.enable_calibration_config(calibration_type)
